package bishi;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        int[] arr = new int[n];
        int[][] arr2 = new int[n][n];
        for(int i=0;i<n;i++){
            arr[i] = in.nextInt();
        }
        int x = 0;
        int y = 0;
        int temp = 0;
        for(int i=0;i<n-1;i++){
            x = in.nextInt();
            y = in.nextInt();
            temp = in.nextInt();
            arr2[x-1][y-1] = temp;
            arr2[y-1][x-1] = temp;
        }
        int t = 0;
        int v = 0;
        for(int i=0;i<q;i++){
            t = in.nextInt();
            v = in.nextInt();
            if(t == 1) arr[v] = arr[v] == 0 ? 1 : 0;
            if(t == 2){
                printSum(v,arr,arr2);
            }
        }
    }

    public static void printSum(int v,int[] arr,int[][] arr2){
        Set<Integer> set = new HashSet<>();
        set.add(v-1);
        System.out.println(sum(v-1,arr,arr2,set,0));
    }

    public static int sum(int v,int[] arr,int[][] arr2,Set<Integer> set,int sum){
//        int sum = 0;
        boolean flag = false;
        for(int i=0;i<arr2.length;i++){
            if(arr2[v][i] != 0 && arr[i] == 1 && !set.contains(i)){
                set.add(i);
                sum += arr2[v][i];
                sum += sum(i,arr,arr2,set,sum);
                flag = true;
            }
        }
        if(!flag)   sum = 0;
        return sum;
    }
}
